package com.six.controller;

import com.six.pojo.BuyAgreement;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.BuyAgreementService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "采购合同接口文档")
@RestController
@RequestMapping("/buyAgreement")
@Slf4j
@CrossOrigin
public class BuyAgreementController {

    @Autowired
    private BuyAgreementService agreementService;

    @PostMapping("/list")
    public Result findList(){
        return null;
    }

    @PostMapping("/add")
    public String add(@RequestBody BuyAgreement agreement){

        //TODO 确认审批人如何添加

        agreement.setId(null);
        agreementService.save(agreement);

        //将添加的合同id传递给前端
        return agreement.getId().toString();
    }

    @PutMapping("/update")
    public Result update(@RequestBody BuyAgreement agreement){

        //TODO 确认审批人如何添加

        agreementService.updateById(agreement);
        return ResultUtils.buildSuccess();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        agreementService.removeById(id);
        return ResultUtils.buildSuccess();
    }
}
